/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package Gui; import Helpers.SwingUtils; import ProtocoleHIDP.HIDP; import ProtocoleHIDP.NetworkClient; import ProtocoleHIDP.PacketCom; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Greenlamp */ public class GetStatDescrActiv extends javax.swing.JFrame { /** * Creates new form GetStatDescrActiv */ NetworkClient socket; public GetStatDescrActiv() { initComponents(); } GetStatDescrActiv(NetworkClient socket) { initComponents(); this.socket = socket; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); Gactivite = new javax.swing.JComboBox(); Gannee = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); Ginscription = new javax.swing.JList(); jLabel5 = new javax.swing.JLabel(); Gmoyenne = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); GecartType = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("GET_STAT_DESCR_ACTIV_RCV"); jLabel2.setText("Nombre d'inscription à l'activité x pour la saison y"); jLabel3.setText("activité:"); jLabel4.setText("année"); Gactivite.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "pedalo", "cracra-hontah", "extreme trek", "orgiac island" })); Gannee.setText("2012"); jButton1.setText("valider"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); Ginscription.setModel(new javax.swing.AbstractListModel() { String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); jScrollPane1.setViewportView(Ginscription); jLabel5.setText("Moyenne: "); Gmoyenne.setText("0"); jLabel7.setText("Ecart-Type: "); GecartType.setText("0"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addComponent(jLabel4)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Gactivite, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(Gannee))) .addComponent(jScrollPane1) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5) .addComponent(jLabel7)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(GecartType) .addComponent(Gmoyenne)))) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(Gactivite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(Gannee, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(Gmoyenne)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7) .addComponent(GecartType)) .addContainerGap(16, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed String activite = Gactivite.getSelectedItem().toString(); String annee = Gannee.getText(); String[] chaine = {activite, annee}; PacketCom packet = new PacketCom(HIDP.GET_STAT_DESCR_ACTIV, (Object)chaine); socket.send(packet); PacketCom packetReponse; try { packetReponse = socket.receive(); traitementPacket(packetReponse); } catch (Exception ex) { Logger.getLogger(GetStatDescrActiv.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jButton1ActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(GetStatDescrActiv.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(GetStatDescrActiv.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(GetStatDescrActiv.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(GetStatDescrActiv.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new GetStatDescrActiv().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox Gactivite; private javax.swing.JTextField Gannee; private javax.swing.JLabel GecartType; private javax.swing.JList Ginscription; private javax.swing.JLabel Gmoyenne; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel7; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables private void traitementPacket(PacketCom packetReponse) { String type = packetReponse.getType(); Object contenu = packetReponse.getObjet(); if(type.equalsIgnoreCase(HIDP.GET_STAT_DESCR_ACTIV_OUI)){ Object[] infos = (Object[]) contenu; String ok = infos[0].toString(); SwingUtils.emptyList(Ginscription); if(ok.equals("Oui")){ SwingUtils.addToList(Ginscription, "Mai: " + infos[1]); SwingUtils.addToList(Ginscription, "Mi-Mai: " + infos[2]); SwingUtils.addToList(Ginscription, "Juin: " + infos[3]); SwingUtils.addToList(Ginscription, "Mi-Juin: " + infos[4]); SwingUtils.addToList(Ginscription, "Juillet: " + infos[5]); SwingUtils.addToList(Ginscription, "Mi-Juillet: " + infos[6]); SwingUtils.addToList(Ginscription, "Aout: " + infos[7]); SwingUtils.addToList(Ginscription, "Mi-Aout: " + infos[8]); SwingUtils.addToList(Ginscription, "Septembre: " + infos[9]); SwingUtils.addToList(Ginscription, "Mi-Septembre: " + infos[10]); SwingUtils.addToList(Ginscription, "Octobre: " + infos[11]); SwingUtils.addToList(Ginscription, "Mi-Octobre: " + infos[12]); Gmoyenne.setText(Double.toString((Double)infos[13])); GecartType.setText(Double.toString((Double)infos[14])); }else{ Gmoyenne.setText("0"); GecartType.setText("0"); } } } }